import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal } from 'antd';
import AddPage from './addPage'
import UpdatePage from './UpdatePage'
import CheckPage from './CheckPage'
import CheckAlonePage from './CheckAlonePage'
import {fetchData} from '../../../components/AjaxConsumer'


export default class ListProSellOutPage extends Component{
    constructor(props) {
        super(props);
        //行操作列表-已弃用
        this.rowOperation = [
            
        ];
        //header 操作列表111
        this.headerOperation = [
            {
                handleName: 'add',
                showName: '创建',
                iconClass: 'add',
                permission: 'sellout-create'
            },
            {
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit',
                permission: 'sellout-edit'
            },
            {
                handleName: 'check',
                showName: '按单审核',
                iconClass: 'eye',
                permission: 'sellout-audit'
            },
            {
                handleName: 'checkAlone',
                showName: '审核',
                iconClass: 'eye',
                // permission: 'sellout-audit'
            }

        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'sellOutId',
            data: [
                {
                    showName: 'sellOutId',
                    columnName: 'sellOutId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '销售出库单号',
                    columnName: 'sellOutNo',
                    columnWidth: 130
                },
                {
                    showName: '型号',
                    columnName: 'model',
                    columnWidth: 120
                },
                {
                    showName: '品名',
                    columnName: 'productName',
                    columnWidth: 100 
                },
                {
                    showName: '定量',
                    columnName: 'density'
                }, 
                {
                    showName: '规格',
                    columnName: 'spec'
                },                                 
                {
                    showName: '类型',
                    columnName: 'type',
                    showOption: [
                        {
                            optionKey: '0',
                            optionShow: '正品'
                        },{
                            optionKey: '1',
                            optionShow: '样品'
                        }
                    ]
                },
                {
                    showName: '等级',
                    columnName: 'grade',
                    showOption: [
                        {
                            optionKey: '1',
                            optionShow: '一等品'
                        },{
                            optionKey: '2',
                            optionShow: '二等品'
                        },{
                            optionKey: '3',
                            optionShow: '处理品'
                        }
                    ]
                }, 
                {
                    showName: '级别',
                    columnName: 'level'
                },                                  
                {
                    showName: '需求数量',
                    columnName: 'requireAmount',
                    columnWidth: 100
                },
                {
                    showName: '实发数量',
                    columnName: 'realAmount',
                    columnWidth: 100
                },
                {
                    showName: '实发重量',
                    columnName: 'weight',
                    columnWidth: 100
                },                
                {
                    showName: '单位',
                    columnName: 'unit',
                    columnWidth: 100
                },
                {
                    showName: '计划日期',
                    columnName: 'outPlanTime',
                    columnWidth: 140
                },
                {
                    showName: '扫描开始时间',
                    columnName: 'scanTimeBegin',
                    columnWidth: 140
                }, 
                {
                    showName: '扫描结束时间',
                    columnName: 'scanTimeEnd',
                    columnWidth: 140
                },                                 
                {
                    showName: '出库状态',
                    columnName: 'sellOutStatus',
                    columnWidth: 120,
                    showOption: [
                        {
                            optionKey: '0',
                            optionShow: '新建'
                        },{
                            optionKey: '1',
                            optionShow: '出库中'
                        },{
                            optionKey: '2',
                            optionShow: '出库完成'
                        },{
                            optionKey: '3',
                            optionShow: '审核通过'
                        }
                        // ,{
                        //     optionKey: '4',
                        //     optionShow: '审核不通过'
                        // }
                    ]
                }
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList: [//下拉框的信息
                      {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            },{
                showName: '类型',
                name: 'type',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },{
                        optionKey: '0',
                        optionShow: '正品'
                    },{
                        optionKey: '1',
                        optionShow: '样品'
                    }
                ]
            },
            {
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList: [//下拉框的信息
                      {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'A',
                        optionShow:'A'
                    },{
                        optionKey:'B',
                        optionShow:'B'
                    },{
                        optionKey:'C',
                        optionShow:'C'
                    }
                ]
            },{
                showName:'计划日期',
                name:'outPlanTime',
                type: 'date',
                maxName:'outPlanTimeMax',
                minName:'outPlanTimeMin'
            },
            {
                showName:'扫描开始时间',
                name:'scanTimeBegin',
                type: 'date',
                maxName:'scanTimeBeginMax',
                minName:'scanTimeBeginMin'
            },
            {
                showName:'扫描结束时间',
                name:'scanTimeEnd',
                type: 'date',
                maxName:'scanTimeEndMax',
                minName:'scanTimeEndMin'
            },
            {
                showName: '需求数量',
                name:'requireAmount',
                type: 'number',
                maxName:'requireAmountMax', //最大值
                minName:'requireAmountMin'  //最小值
            },
            {
                showName:'实发数量',
                name:'realAmount',
                type:'number',
                maxName:'realAmountMax',
                minName:'realAmountMin'
            },
            {
                showName:'实发数量',
                name:'realAmount',
                type:'number',
                maxName:'realAmountMax',
                minName:'realAmountMin'
            },
            {
                showName:'实发重量',
                name:'weight',
                type:'number',
                maxName:'weightMax',
                minName:'weightMin'
            },
            {
                showName:'出库状态',
                name:'sellOutStatus',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },{
                        optionKey: '0',
                        optionShow: '新建'
                    },{
                        optionKey: '1',
                        optionShow: '出库中'
                    },
                    {
                        optionKey: '2',
                        optionShow: '出库完成'
                    },{
                        optionKey: '3',
                        optionShow: '审核通过'
                    }
                ]
            },
            {
                showName: '单位',
                name: 'unit',
                type: 'select',
                url:'/base/dic/get/unit'
            }
        ];

    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'exp'){
            // this.expHandle(rowObj);
        }else if(strHandles === 'add'){
            this.addHandle(rowObj);
        }else if(strHandles == 'edit'){
            this.editHandle(rowObj);
        }else if(strHandles == 'check'){
            this.checkHandle(rowObj);
        }else if(strHandles == 'checkAlone'){
            this.checkAloneHandle(rowObj);
        }
    }

    checkHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.checkPage.checkHandle(rowObj);
        }
    };

    checkAloneHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.checkAlonePage.checkAloneHandle(rowObj);
        }
    };


    editHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updatePage.editHandle(rowObj);
        }
    };

    //按照库位新增
    addHandle = () => {
        this.refs.addPage.addHandle();
    };

    // componentWillMount() {
    //     const dicType = 'model_type_p';
    //     const options= {
    //         url: '/base/dic/get/' + dicType,
    //         type: 'get',
    //         condition:{}
    //     };
    //     //先写死，后面再改
    //     fetchData(this, options, this.dicInitCallBackHandle);
    // }

    // //下拉框 初始化
    // dicInitCallBackHandle = (resData)=>{
    //     //alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';
    //     tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map( (e,index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });

    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[5].showOption = optionList;
    //     this.searchComponentData[0].optionList = optionList;
    // }

    //刷新列表
    refreshHandle = () => {
        this.refs.proSellOutList.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'proSellOutList'
                    title="成品销售出库查询"
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/product/prosellout/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
                <AddPage
                    ref="addPage"
                    refreshHandle = {this.refreshHandle}
                />
                <UpdatePage
                    ref="updatePage"
                    refreshHandle = {this.refreshHandle}
                />

                <CheckPage
                    ref="checkPage"
                    refreshHandle = {this.refreshHandle}
                />
                <CheckAlonePage
                    ref="checkAlonePage"
                    refreshHandle = {this.refreshHandle}
                />
            </div>
        )
        
    }

}